// pages/classify/classify.js
var source = require('../../data/source');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    age1:"0",
    age2:"100",
    sex:"妖",
    heig1:"0",
    heig2:"300",
    info:[],
    list:[],
    list1:[],
    item:"",
    tab:"0",
    tab1:"0",
    tab2:"0",
    flag: false,
    show: true,
    //名字
    provinceName: [],
    provinceCode: [],
    provinceIndex: '',
   cityName: [],
    cityCode: [],
    cityIndex: '',
    countyName: [],
    countyCode: [],
    countyIndex: '',
    pro: 0,
    cit:  0,
    cou: 0,
  },
  putinfo:function(e){
    console.log(e.currentTarget.dataset.id);
    wx.navigateTo({
      url: '/pages/Information/Information?id='+ e.currentTarget.dataset.id,
    })
  },
  chengeItem:function(e){
         this.setData({
          tab:e.target.dataset.tab,
          age1:e.target.dataset.age1,
          age2:e.target.dataset.age2
        })
        console.log(this.data.tab)
  },
  

  chengeItem1:function(e){
     this.setData({
      tab1:e.target.dataset.tab,
      sex:e.target.dataset.sex
    })
    console.log(this.data.tab1)
},

chengeItem2:function(e){
   this.setData({
    tab2:e.target.dataset.tab,
    heig1:e.target.dataset.heig1,
    heig2:e.target.dataset.heig2
  })
  console.log(this.data.tab2)
  console.log(this.data.heig1)
  console.log(this.data.heig2)
},

  
  onLoad: function () {
     wx.request({
      url: 'http://123.57.174.220:8085/getAllMatching',
      method:"GET",
      success:(res)=>{
        console.log(res.data)
        this.setData({
          list:res.data
        })
      }
    })

    wx.request({
      url: 'http://123.57.174.220:8085/UserAll',
      method:'GET',
      success:(res)=>{
        console.log(res.data);
        this.setData({
          info:res.data
        })
        for (let index = 0; index < this.data.info.length; index++) {
          const element = this.data.info[index];
          for (let i = 0; i < this.data.list.length; i++) {
            const ele = this.data.list[i];
            if (element.id == ele.id) {
              const list = {
                id:element.id,
                name:element.name,
                headPhoto:element.headPhoto,
                age:ele.age,
                city:ele.city,
                sex:ele.sex,
                heig:ele.heig
              }
              this.data.list1.push(list)
            }
            
          }
        }
        this.setData({
          list1:this.data.list1
        })
        console.log(this.data.list1);
      }
    })

    // 初始化数据

    this.setSource()

  },

 setSource: function (pro, cit, cou) {

    // pro代表滚动时省的下标  cit市的下标  cou区的下标

    var pro = pro || 0 ;  // 如果没有传值  就把0赋值给它
    var cit = cit || 0 ;
    var cou = cou || 0 ;

    // 设置省的数据

    var province = source['100000'] //100000表示省的对象
    console.log(province);
    var provinceName = [];
    var provinceCode = [];
    for (var item in province) {
      console.log(item);
      provinceName.push(province[item]);
      provinceCode.push(item);
    }
    console.log(provinceName);//全部省的数组
    this.setData({
      provinceName: provinceName,
      provinceCode: provinceCode
    })

    // 设置市的数据  provinceCode省的编号数组

    var city = source[provinceCode[pro]];
    var cityName = [];
    var cityCode = [];
    for (var item in city) {
      cityName.push(city[item]);
      cityCode.push(item);
    }

    this.setData({
      cityName: cityName,
      cityCode: cityCode
    });

    // 设置区的数据

    var county = source[cityCode[cit]]
    var countyName = [];
    var countyCode = [];
    for (var item in county) {
      countyName.push(county[item])
      countyCode.push(item)
    }
    this.setData({
      countyName: countyName,
      countyCode: countyCode
    });
  },

  //滚动时触发

  pickerChange: function (e) {

    console.log(e);

    var pro = e.detail.value[0];

    var cit = e.detail.value[1];

    var cou = e.detail.value[2];

    this.setSource(pro, cit, cou);

    this.setData({

      pro: pro,

      cit: cit,

      cou: cou,

    });

  },

  //点击时显示选项

  showPicker: function () {

    this.setData({

      show: false

    })

  },

  //点击时隐藏选项

  cancel: function () {

    this.setData({

      show: true

    });

  },

  //点击确定按钮时触发

  sure: function () {
    this.setData({
      provinceIndex: this.data.pro,
      cityIndex: this.data.cit,
      countyIndex: this.data.cou,
      flag: true,
    });

    this.cancel(); //关闭选项卡片

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
   
    

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})